package com.steven.im.ui.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.steven.im.R;
import com.steven.im.base.BaseActivity;
import com.steven.im.base.Constant;
import com.steven.im.entity.IMGroupNameEntity;
import com.steven.im.utils.FileUtils;
import com.steven.im.utils.ScreenUtil;
import com.steven.im.utils.TitleBuilder;
import com.steven.im.utils.ToastUtil;
import com.steven.im.widget.CenterDialog;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

import static com.steven.im.base.Constant.NEW_GROUP_NAME;

public class IMModifyRemarkActivity extends BaseActivity {
    @BindView(R.id.tv_groupName)
    TextView tvGroupName;
    @BindView(R.id.et_remark)
    EditText etRemark;

    @Override
    public void setListen() {

    }

    @Override
    public void setTitleBarColor() {
        new TitleBuilder(this).setTitleText(getString(R.string.changeRemark))
                .setLeftIcoListening(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        finish();
                    }
                });

    }

    @Override
    public int intiLayout() {
        return R.layout.activity_im_modifyremark;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {
      etRemark.setSelection(etRemark.getText().toString().length());
    }

    @OnClick({R.id.rl_selectGroup, R.id.ll_newGroup})
    public void onViewClicked(View view) {
        if (ScreenUtil.isFastClick()) {
            return;
        }
        switch (view.getId()) {
            case R.id.rl_selectGroup://选择分组
                List<IMGroupNameEntity> list = new ArrayList<>();
                for (int i = 0; i < 8; i++) {
                    IMGroupNameEntity imGroupNameEntity = new IMGroupNameEntity();
                    imGroupNameEntity.setName("亨通" + i);
                    list.add(imGroupNameEntity);
                }

                new CenterDialog(R.layout.im_group_dialog, IMModifyRemarkActivity.this).showGroup(list, tvGroupName);
                break;
            case R.id.ll_newGroup://新建分组
                startActivityForResult(new Intent(this, IMAddNewGroupActivity.class)
                        , NEW_GROUP_NAME);
                break;

        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //修改完返回的分组名
        if (requestCode == NEW_GROUP_NAME && resultCode == RESULT_OK) {
            assert data != null;
            String groupName = data.getStringExtra("groupName");
            if (!"".equals(groupName)) {
                tvGroupName.setText(groupName);
            }
        }
    }
}
